import { Color4B, TextAreaMsgEntity, ViewRect } from '../../entity/WorkerMsgEntity';

export class TextAreaWorkerMsgHandler {
    private static workerPort;

    static init(workerPort) : void {
        console.log("[cocos] textArea init Callback");
        TextAreaWorkerMsgHandler.workerPort = workerPort;
    }

    static createTextArea(viewTag: number, x: number, y: number, w: number, h: number, paddingW: number, paddingH: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity( 'createTextArea', viewTag);
        let viewRect: ViewRect = new ViewRect(x, y, w, h);
        textAreaMsgEntity.viewRect = viewRect;
        textAreaMsgEntity.paddingW = paddingW;
        textAreaMsgEntity.paddingH = paddingH;
        console.log("[cocos] message posted")
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static removeTextArea(viewTag: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('removeTextArea', viewTag);
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaViewRect(viewTag: number, x: number, y: number, w: number, h: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaViewRect', viewTag);
        let viewRect: ViewRect = new ViewRect(x, y, w, h);
        textAreaMsgEntity.viewRect = viewRect;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaVisible(viewTag: number, visible: boolean) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaVisible', viewTag);
        textAreaMsgEntity.visible = visible;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaBold(viewTag: number, isBold: boolean) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaBold', viewTag);
        textAreaMsgEntity.isBold = isBold;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaEditable(viewTag: number, editable: boolean) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaEditable', viewTag);
        textAreaMsgEntity.editable = editable;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setCurrentText(viewTag: number, text: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setCurrentText', viewTag);
        textAreaMsgEntity.text = text;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaFontSize(viewTag: number, size: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaFontSize', viewTag);
        textAreaMsgEntity.fontSize = size;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaFontColor(viewTag: number, r: number, g: number, b: number, a: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaFontColor', viewTag);
        let color: Color4B = new Color4B(r, g, b, a);
        textAreaMsgEntity.color = color;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaPlaceHolderFontColor(viewTag: number, r: number, g: number, b: number, a: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaPlaceHolderFontColor', viewTag);
        let color: Color4B = new Color4B(r, g, b, a);
        textAreaMsgEntity.placeHolderColor = color;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaPlaceHolderFontSize(viewTag: number, size: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaPlaceHolderFontSize', viewTag);
        textAreaMsgEntity.placeHolderSize = size;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaPlaceHolder(viewTag: number, text: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaPlaceHolder', viewTag);
        textAreaMsgEntity.placeHolderText = text;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaMaxLength(viewTag: number, maxLength: number) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaMaxLength', viewTag);
        textAreaMsgEntity.maxLength = maxLength;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaAlign(viewTag: number, align: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaAlign', viewTag);
        textAreaMsgEntity.align = align;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setNativeInputMode(viewTag: number, inputMode: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setNativeInputMode', viewTag);
        textAreaMsgEntity.inputMode = inputMode;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setNativeInputFlag(viewTag: number, isSecure: boolean) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity( 'setNativeInputFlag', viewTag);
        textAreaMsgEntity.isSecure = isSecure;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setNativeReturnKey(viewTag: number, enterKey: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity( 'setNativeReturnKey', viewTag);
        textAreaMsgEntity.enterKey = enterKey;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaFontPath(viewTag: number, fontPath: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaFontPath', viewTag);
        textAreaMsgEntity.fontPath = fontPath;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static setTextAreaPlaceHolderFontPath(viewTag: number, fontPath: string) : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('setTextAreaPlaceHolderFontPath', viewTag);
        textAreaMsgEntity.placeHolderFontPath = fontPath;
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }

    static hideAllTextArea() : void {
        let textAreaMsgEntity: TextAreaMsgEntity = new TextAreaMsgEntity('hideAllTextArea');
        TextAreaWorkerMsgHandler.workerPort.postMessage(textAreaMsgEntity);
    }
}